home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1984 January to June / Ahoy_Magazine_84-Jan-Jun_1984_Double_L.d64 / commodares #5-1 (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  540b  |  16 lines

  1. 0 rem--ahoy!--may issue--commodares #5--prog page 91
  2. 1 rem << problem 4-1 : squared sum >>
  3. 2 rem - find numbers equal to the square of the sum of their digits
  4. 5 for j=1 to 100
  5. 10 sum=0 : rem initial sum of digits
  6. 15 jj=j*j : rem jj is a square
  7. 20 j$=str$(jj) :rem convert jj to a string variable j$
  8. 25 rem -- lines 30 - 60 take each digit of j$ and add its value to sum ---
  9. 30 for d=2 to len(j$)
  10. 40 v=val(mid$(j$,d,1))
  11. 50 sum=sum+v
  12. 60 next d
  13. 65 ss=sum*sum : rem > get the square of the sum of the digits
  14. 70 if abs(ss-jj)<1e-4 then print jj"is a solution"
  15. 80 next j
  16.